home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
et
/
et3_0-a1.lha
/
et3
/
src
/
WindowSystem.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-08-26
|
7KB
|
318 lines
#ifdef __GNUG__
#pragma implementation
#endif
#include "WindowSystem.h"
#include "Class.h"
#include "CLib.h"
#include "String.h"
#include "Error.h"
#include "WindowPort.h"
#include "ClipBoard.h"
#include "DevBitmap.h"
#include "StreamConnection.h"
#include "OrdColl.h"
#include "ClassManager.h"
#include "Env.h"
#include "Look.h"
#include "TextItem.h"
#include "CompVObject.h"
#include "Data.h"
#include "MemBuf.h"
extern StreamConnection *gRpc;
WindowSystem *gWindowSystem;
int gDepth= 1;
bool gColor;
int gMaxDepth;
bool gGreyScale;
//---- RemoteData --------------------------------------------------------------
class RemoteData : public StreamBufData {
int holder;
Class *w;
public:
RemoteData(int from, Symbol t, Class *cl);
StreamBuf *GetStreamBuf();
bool CanConvert(Class *want);
Object *AsObject(Class *want);
bool IsETFormat()
{ return TRUE; }
};
RemoteData::RemoteData(int from, Symbol t, Class *cl) : StreamBufData(0, t)
{
holder= from;
classtype= cl;
}
StreamBuf *RemoteData::GetStreamBuf()
{
if (sb == 0) {
char *buf= 0;
int len= 0;
// get clipboard from server
gRpc->Talk(holder, "clipboard:get",
form("%s %s", cDocTypeET.AsString(), w->Name()), -1, &buf, &len);
if (len > 0) {
sb= new MemBuf;
sb->sputn(buf, len);
((MemBuf*)sb)->SwitchToRead();
}
SafeDelete(buf);
}
return sb;
}
bool RemoteData::CanConvert(Class *want)
{
bool can= FALSE;
char *ret= 0;
int retlen= 0;
gRpc->Talk(holder, "clipboard:canconvert", want->Name(), -1, &ret, &retlen);
if (ret)
can= strcmp(ret, "yes") == 0;
SafeDelete(ret);
return can;
}
Object *RemoteData::AsObject(Class *want)
{
if (gDebug)
fprintf(stderr, "RemoteData::AsObject: is:%s want:%s %d\n",
Type().AsString(), want->Name(), IsETFormat());
w= want;
return Data::AsObject(want);
}
//---- Clipboard support -------------------------------------------------------
int WindowSystem::DevHaveSelection(Data *data)
{
char *args= data->Type().AsString();
if (data->GetClassType())
args= form("%s %s", args, data->GetClassType()->Name());
gRpc->Talk(0, "clipboard:holder", args);
return 0;
}
void WindowSystem::ExtCommand(int from, char *req, char *args, int,
char *&ret, int &retlen)
{
Class *theclasstype= 0;
char type[100], classtype[100];
if (strcmp(req, "get") == 0) {
if (sscanf(args, "%s %s", type, classtype) == 2)
theclasstype= gClassManager->Find(classtype);
ret= gClipBoard->GetExtSelection(&retlen, Symbol(type), theclasstype);
} else if (strcmp(req, "holder") == 0) {
if (sscanf(args, "%s %s", type, classtype) == 2)
theclasstype= gClassManager->Find(classtype);
gClipBoard->SetData(new RemoteData(from, Symbol(type), theclasstype));
} else if (strcmp(req, "remove") == 0) {
gClipBoard->SetData(0);
} else if (strcmp(req, "canconvert") == 0) {
bool can= FALSE;
if (sscanf(args, "%s", classtype) == 1) {
theclasstype= gClassManager->Find(classtype);
if (theclasstype) {
Data *data= gClipBoard->GetType();
if (data)
can= data->CanConvert(theclasstype);
}
}
ret= can ? "yes" : "no";
}
}
void WindowSystem::DevCheckSelection()
{
}
//---- MenuBorderItem ----------------------------------------------------------
class MenuBorderItem: public CompositeVObject {
Layout *l;
public:
MenuBorderItem(VObject *inner, VObject *title= 0)
: CompositeVObject(cIdNone, inner, title, 0)
{ l= title ? gLook->PopUpMenuLayout() : gLook->PullDownMenuLayout(); }
~MenuBorderItem()
{ Remove(At(0)); /* avoid deletion of inner */ }
void Draw(Rectangle r)
{ l->Adorn(this, r); }
Metric GetMinSize()
{ return l->GetMinSize(this); }
void SetOrigin(Point at)
{ VObject::SetOrigin(at); l->SetOrigin(this, at); }
void SetExtent(Point e)
{ VObject::SetExtent(e); l->SetExtent(this, e); }
};
//---- WSInit ------------------------------------------------------------------
bool testwindow= FALSE;
void WindowSystem::WSInit()
{
if (gWindowSystem)
return;
InitSystem();
if (! gInMain) {
fprintf(stderr, "--- InitWindowSystem called before ETInit\n");
CLib::Abort();
}
batch= Env::GetValue("WindowSystem.DoubleBuffer", TRUE);
gMaxDepth= Env::GetValue("WindowSystem.MaxDepth", 32);
gGreyScale= Env::GetValue("WindowSystem.GreyScale", FALSE);
testwindow= Env::GetValue("WindowSystem.Test", FALSE);
if (gWindowSystem == 0 && CLib::Getenv("DISPLAY"))
gWindowSystem= (WindowSystem*) gClassManager->Load("xserver", "XWinSystem");
if (gWindowSystem == 0 && CLib::Getenv("WINDOW_PARENT"))
gWindowSystem= (WindowSystem*) gClassManager->Load("sun", "SunWindowSystem");
if (gWindowSystem == 0) {
fprintf(stderr, "can't find window system\n");
CLib::Exit(0); // give up
}
gWindowSystem->Init();
}
//---- WindowSystem ------------------------------------------------------------
NewMetaImpl(WindowSystem, SysEvtHandler, (TP(allwins),
T(lasttime), TB(fullscreen), TP(grabport), T(Clicks), T(screenRect), T(batch)));
bool WindowSystem::batch;
u_long WindowSystem::lasttime;
bool WindowSystem::fullscreen;
WindowPort *WindowSystem::grabport;
Rectangle WindowSystem::screenRect= Rectangle(0, 0, 1152, 900);
Token WindowSystem::lastClick;
int WindowSystem::Clicks;
OrdCollection *WindowSystem::allwins;
WindowColorMap *WindowSystem::wcmap;
WindowSystem::WindowSystem() : SysEvtHandler(0)
{
}
WindowSystem::~WindowSystem()
{
if (gWindowSystem == this)
gWindowSystem= 0;
SafeDelete(gFontManager);
SafeDelete(gInkManager);
SafeDelete(allwins);
//SafeDelete(wcmap);
}
void WindowSystem::InitNew()
{
if (allwins == 0)
allwins= new OrdCollection;
}
void WindowSystem::Init()
{
gColor= gDepth > 1;
gFontManager= MakeFontManager();
if (gFontManager == 0)
Fatal("Init", "no font manager");
if (gFontManager->Init())
Fatal("Init", "initialization of font manager failed");
gInkManager= new InkManager();
if (gDepth > 1) {
gHighlightColor= new_RGBColor(0, 255, 0); // light green
Env::Bind(gHighlightColor, "WindowSystem.HighlightColor");
} else
gHighlightColor= gInkXor;
MakeLook(Env::GetValue("WindowSystem.Motif", 0));
}
VObject *WindowSystem::MakeWindowBorder(WindowType wt, VObject *in,
char *title, bool, bool)
{
switch (wt) {
case eWinPulldownMenu:
return new MenuBorderItem(in);
case eWinPopupMenu:
return new MenuBorderItem(in, new TextItem(title));
default:
return in;
}
}
void WindowSystem::SetWait()
{
allwins->ForEach(WindowPort,DevSetCursor)(eCrsHourglass);
}
void WindowSystem::ResetWait()
{
Iter next(allwins);
WindowPort *wp;
while (wp= (WindowPort*) next())
wp->DevSetCursor(wp->GetCursor());
}
void WindowSystem::Update()
{
allwins->ForEach(WindowPort,DevUpdate)();
}
WindowPort *WindowSystem::MakeWindow(Window*, WindowType, GrCursor)
{
return 0;
}
void WindowSystem::RemoveWindow(WindowPort *wp)
{
if (allwins)
allwins->RemovePtr(wp);
}
void WindowSystem::AddWindow(WindowPort *wp)
{
if (allwins)
allwins->Add(wp);
}
FontManager *WindowSystem::MakeFontManager()
{
return 0;
}
DevBitmap *WindowSystem::MakeDevBitmap(Point, u_short*, u_short, bool, u_short)
{
return 0;
}
void WindowSystem::graphicDelay(u_int duration)
{
gSystem->Wait(duration);
}
void WindowSystem::DevBell(long)
{
}